package com.example.hal.server;

import static com.googlecode.objectify.ObjectifyService.ofy;

import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

import org.restlet.resource.ServerResource;

import com.example.hal.model.Domaine;
import com.example.hal.model.Utilisateur;
import com.example.hal.model.Departement;
import com.googlecode.objectify.ObjectifyService;

public class DepartementController	extends ServerResource implements
	 DepartementControllerInterface {
	static{

		 ObjectifyService.register(Departement.class);
	}

	public DepartementController() {
		// TODO Auto-generated constructor stub
	}
	
	
	
	@Override
	public void create(Departement departement) {
		// TODO Auto-generated method stub

		Departement v=new Departement();
		v.setCodePostal(departement.getCodePostal());
		v.setLatitude(departement.getLatitude());
		v.setLongitude(departement.getLongitude());
		v.setNom(departement.getNom());
		 ofy().save().entity(v).now(); 
		 
	}
	@Override
	public DepartementContainer getAllDepartement() {
		// TODO Auto-generated method stub
	        
		DepartementContainer content = null;
		String tmp;

		 Logger log = Logger.getLogger(DepartementController.class.getName());

	        log.severe("getAllDepartement.");
//filter("CodePostal","51").
		 List<Departement> departements = ofy().load().type(Departement.class).filter("CodePostal","52").list();
	     content = new DepartementContainer();
		 content.setDepartement_list(departements);
		 for(Departement d : departements)
		 {
			 tmp=d.getNom();
			 log.severe(d.getNom());
		 }
		 return content;
		 
	}


	@Override
	public Departement getDepartement(String codePostal) {
		// TODO Auto-generated method stub
	        
		DepartementContainer content = null;
		String tmp;

		 Logger log = Logger.getLogger(DepartementController.class.getName());

	        log.severe("getAllDepartement.");
//filter("CodePostal","51").
		 Departement departement = ofy().load().type(Departement.class).filter("CodePostal",codePostal).first().now();
	   
		 return departement;
		 
	}
}
